package com.jddup.test.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.jddup.common.pojo.JddupConfig;
import com.jddup.program.Jddup;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ZZB on 2017/12/21.
 */
@Configuration
@ServletComponentScan("com.jddup.test")
public class WebConfig extends WebMvcConfigurerAdapter {
    @Bean
    public Jddup Jddup(){
        JddupConfig jddupConfig = new JddupConfig();
        jddupConfig.setOpenCompare( true);
        Map<String,DataSource> dataSourceMap  = new HashMap<>();
//        {
//            DruidDataSource druidDataSource = new DruidDataSource();
//            druidDataSource.setUrl("jdbc:postgresql://39.108.66.189:5432/db_dongdongqiang");
//            druidDataSource.setUsername("root");
//            druidDataSource.setPassword("Jre1S12dsay7sd1mqsa3ni");
//            dataSourceMap.put("postgresql",druidDataSource);
//        }
        {
            DruidDataSource druidDataSource = new DruidDataSource();
            druidDataSource.setUrl("jdbc:mysql://127.0.0.1:3306/db_huobi_dm_robot?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC");
            druidDataSource.setUsername("root");
            druidDataSource.setPassword("123456");
            druidDataSource.setMaxActive(10);
            druidDataSource.setDefaultAutoCommit(true);
            druidDataSource.setValidationQueryTimeout(10);
            druidDataSource.setValidationQuery("select 'x'");
            dataSourceMap.put("mysql",druidDataSource);
        }
        jddupConfig.setDataSourceMap(dataSourceMap);

        Map<String,List<String>> scanPackageMap = new HashMap<>();
//        {
//            List<String > scanPackage = new ArrayList<>();
//            scanPackage.add("com.jddup.test.pojo.postgresql");
//            scanPackageMap.put("postgresql",scanPackage);
//        }
        {
            List<String> scanPackage = new ArrayList<>();
            scanPackage.add("com.jddup.test.pojo.mysql");
            scanPackageMap.put("mysql",scanPackage);
        }

        jddupConfig.setDataSourceScanPackageMap(scanPackageMap);
        return new Jddup(jddupConfig);
    }
}
